﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBModel
{
    public partial class Employment
    {
        public override string ToString()
        {
            return string.Format("{0}, {1}, {2} -> {3} ", EmploymentId, CompanyName,
                StartDate.ToShortDateString(), EndDate.ToShortDateString());
        }

        public string ToHtml()
        {
            return string.Format("{0} &ndash; {1}<br /> {2}<br /> {3}<br />{4}<br />",
                StartDate.ToShortDateString(), EndDate.ToShortDateString(),
                Titel, CompanyName, WorkDescription);
        }
    }

    public static class EmploymentDB
    {
        public static Employment GetEmploymentById(int id)
        {
            return DB.Context.Employments
                .Where(e => e.EmploymentId == id)
                .SingleOrDefault(e => e.IsDeleted == false);
        }
            
        public static bool DeleteEmploymentById(int id)
        {
            Employment employmentToDelete = GetEmploymentById(id);
            if (employmentToDelete != null)
            {
                employmentToDelete.IsDeleted = true;
                int affectedRows= DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
